import { Button, Col, Descriptions, Form, Input, message, Radio, Row, Select } from 'antd'
import React, { useEffect, useState } from 'react'
const { Option } = Select;
import request from '@/http';
import SecurityService from '@/pages/login/service';

export default function My() {
    const [formObject] = Form.useForm();

    useEffect(() => {
        formObject.setFieldsValue({
            userName:SecurityService.getSecurity().name,
            userSex:SecurityService.getSecurity().userSex,
            userAge:SecurityService.getSecurity().userAge,
            userTelphone:SecurityService.getSecurity().userTelphone
            });
        }, []);


    const onFinish = async (values: any) => {
        await request.post('/api/Users/EditUsers',{
            id:SecurityService.getSecurity().id,
            userTelphone:values.userTelphone,
            userAge: parseInt(values.userAge),
            userName:values.userName,
            userSex:values.userSex
          }).then((response:any)=>{
            if(response.code==200){
              SecurityService.saveSecurity({userSex:response.data.userSex,userAge:response.data.userAge,userTelphone:response.data.userTelphone,id:response.data.id,name:response.data.userName,token:response.data.token,role:response.data.role})
              message.success(response.message);
            }else{
              message.success(response.message);
            }
          })
    };
      
    return (
        <>
            <div className="as2">
            <Form
              name="normal_login"
              className="login-form"
              initialValues={{ roleType: '1', remember: true }}
              onFinish={onFinish}
              form={formObject}
            >
               <Row gutter={24} justify='center' >
            <Col span={20} key='1'>
              <Form.Item
                label="姓名"
                name="userName"
                rules={[
                  { required: true, whitespace: true, message: '不能为空!' },
                  { max: 30, message: '最大长度不能超过30!' },
                  ]}
              >
                <Input placeholder="请录入" />
              </Form.Item>
            </Col>
            <Col span={20} key='2'>
              <Form.Item
                label="性别"
                name="userSex"
                rules={[
                  { required: true, message: '不能为空!' }
                  ]}
              >
                <Radio.Group>
                            <Radio value={0}>男</Radio>
                            <Radio value={1}>女</Radio>
                        </Radio.Group>
              </Form.Item>
            </Col>
            <Col span={20} key='3'>
              <Form.Item
                label="年龄"
                name="userAge"
                rules={[
                  { required: true, message: '不能为空!' }
                  ]}
              >
                <Input placeholder="请录入" />
              </Form.Item>
            </Col>
            <Col span={20} key='4'>
              <Form.Item
                label="电话（账号）"
                name="userTelphone"
                rules={[
                  { required: true, message: '不能为空!' }
                  ]}
              >
                <Input placeholder="请录入" />
              </Form.Item>
            </Col>
            <Col span={24} style={{margin:'10px 0'}} key='5'>
            </Col>
            <Col>
            <Form.Item>
              <Button
                style={{marginRight:10}}
                htmlType='submit'
              >确认</Button>
              </Form.Item>
            </Col>
            <Col span={24}>
            <Button type='link'>修改密码</Button>
            </Col>
          </Row>
            </Form>
        </div>
        </>
    )
}
